package com.gdkj.third;

import com.alibaba.fastjson.JSONObject;
import com.gdkj.params.ExaminePlatformMixParams;
import com.gdkj.util.HttpUtils;
import com.gdkj.vo.ExaminePlatformMixVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
public class ExaminePlatformService implements IExaminePlatform{
    /**
     * 混合审核地址
     */
    @Value("${EXAMINE_PLATFORM_WORD_URL}")
    private String httpRequestUrl;
    /**
     * 混合审核
     * @param examinePlatformMixParams examinePlatformMixParams
     * @return ExaminePlatformMixVO
     * @throws Exception Exception
     */
    @Override
    public ExaminePlatformMixVO mixAudit(ExaminePlatformMixParams examinePlatformMixParams) throws Exception {
        ExaminePlatformMixVO returnData;
        String httpSign = examinePlatformMixParams.getBussTypeId() + examinePlatformMixParams.getUuid() + examinePlatformMixParams.getBussSecret();
        // 构造参数
        Map<String, String> requestParam = new HashMap<>();
        requestParam.put("uuid", examinePlatformMixParams.getUuid());
        requestParam.put("bussTypeId", examinePlatformMixParams.getBussTypeId());
        requestParam.put("sign", DigestUtils.md5DigestAsHex(httpSign.getBytes()));
        if (examinePlatformMixParams.getUid() == null) {
            requestParam.put("uid", "");
        } else {
            requestParam.put("uid", examinePlatformMixParams.getUid());
        }
        if (examinePlatformMixParams.getContent() == null) {
            requestParam.put("content", "");
        } else {
            requestParam.put("content", examinePlatformMixParams.getContent());
        }
        if (examinePlatformMixParams.getImageUrl() == null) {
            requestParam.put("imageUrl", "");
        } else {
            requestParam.put("imageUrl", examinePlatformMixParams.getImageUrl());
        }
        if (examinePlatformMixParams.getContentFrom() == null) {
            requestParam.put("from", "");
        } else {
            requestParam.put("from", examinePlatformMixParams.getContentFrom());
        }

        String httpReturnData = HttpUtils.doPostFormData(httpRequestUrl, requestParam, new HashMap<>());
        returnData = JSONObject.parseObject(httpReturnData, ExaminePlatformMixVO.class);

        return returnData;
    }
}
